package com.ruoyi.web.controller.system;
/**
 * ClassName: SysNewsController <br/>
 * Description: <br/>
 * date: 2020/3/24 9:32<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysClient;
import com.ruoyi.system.domain.SysNews;
import com.ruoyi.system.service.IClientService;
import com.ruoyi.system.service.INewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: ruoyi
 * @description:
 * @author: hesion
 * @create: 2020-03-24 09:32
 **/
@Controller
@RequestMapping("/system/client")
public class SysClientController extends BaseController {
    String prefix = "system/client";
    @Autowired
    IClientService clientService;
    @GetMapping()
    public String taskPage() {
        return prefix + "/client";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysClient sysClient) {
        startPage();
        List<SysClient> list = clientService.selectClientByPage(sysClient);
        return getDataTable(list);
    }

    @GetMapping("/edit/{id}")
    public String editPage(@PathVariable String id, ModelMap mmap) {
        mmap.put("clients",clientService.selectClientById(id));
        return prefix+"/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(SysClient sysClient) {
        sysClient.setUpdateBy(ShiroUtils.getLoginName());
        Integer result = clientService.edit(sysClient);
        if (result > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("修改失败!请重试");
        }
    }
    @GetMapping("/add")
    public String addPage() {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(SysClient sysClient) {
        sysClient.setCreateBy(ShiroUtils.getLoginName());
        Integer result = clientService.add(sysClient);
        if (result > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("新增失败!请重试");
        }
    }
    @PostMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable String id){
        Integer remove=clientService.remove(id);
        if(remove>0){
            return AjaxResult.success("删除成功!");
        }else {
            return AjaxResult.error("删除失败!");
        }
    }
}
